package com.stsdai.shop.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CookieValue;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stsdai.common.pojo.StsdaiResult;
import com.stsdai.manager.pojo.OrderItem;
import com.stsdai.manager.pojo.User;
import com.stsdai.order.service.OrderItemService;
import com.stsdai.sso.service.UserService;

@Controller
@RequestMapping("order")
public class OrderController {

	@Autowired
	private OrderItemService orderItemService;

	@Autowired
	private UserService userService;

	@RequestMapping(method = RequestMethod.GET)
	@ResponseBody
	public StsdaiResult<OrderItem> queryItemByPage(@CookieValue(value = "STSD_TICKET",defaultValue = "MyJsessionId") String ticket, @RequestParam(value = "page", defaultValue = "1") Integer page,
			@RequestParam(value = "rows", defaultValue = "30") Integer rows) {
		// 通过shopTicket获取卖家对象,并封装查询条件
		Long shopid = null;
		User user = userService.queryUserByTicket(ticket);
		if(user != null){
			Long shopId = user.getId();
			// 根据shopid分页查询商品
			StsdaiResult<OrderItem> stsdaiResult = this.orderItemService.queryOrderItemByShopId(shopId, page, rows);
			return stsdaiResult;
		}
		return null;
	}
}
